home *** CD-ROM | disk | FTP | other *** search
/ Clipper Collection / Clipper Collection.iso / clipper7 / nannws12.arc / FLIPSTR.ASM < prev    next >
Assembly Source File  |  1986-11-25  |  5KB  |  126 lines

  1.     TITLE FLIPSTR
  2.     PAGE ,132
  3. ;
  4. ;   Title:    TURNIT3.ASM
  5. ;   Author:   F. Ho
  6. ;   Date:     8th July 1986
  7. ;   Syntax:   ? TURN(expC)
  8. ;             where: -expC is the character string expression 
  9. ;                     to be reversed
  10. ;   Note:     - reverses the order of the string passed
  11. ;             - can only process a MAX of 60 characters
  12.  
  13. ;   Revised PBaenziger, pbprograms, 1215 Lane, Kalamzoo, MI 49001
  14. ;   (616) 349-9720 (Evenings), 323-7392 (Days, 8-4:30 EDT)
  15.  
  16. ;   Simplified, using string instructions
  17. ;   Maximum string length MAXLEN - set for debugging to 10 decimal
  18. ;
  19. public    TURN      ; this public statement makes this
  20. ;                  ; routine accessible to the 'public'
  21. ;
  22. extrn    _PARC:far           ; Clipper's character 'getter'
  23. extrn    _RETC:far           ; Clipper's character 'returner'
  24. ;
  25. ;
  26. MAXLEN   EQU       10             ; Maximum string length
  27.  
  28. DGROUP   GROUP     datasg         ; Clipper's Data Segment
  29.  
  30. ; the 'public' in the next statement combines the datasg
  31. ; to Clipper's DGROUP group
  32. datasg   segment   public    'DATA'
  33.  
  34. RETVAL   db        MAXLEN + 1 dup(?)   ; Space for flipped string + NUL
  35.  
  36. datasg   ends                     ; end of datasg (in DGROUP)
  37. ;
  38. ;
  39. _prog    segment
  40. assume   cs:_prog,ds:DGROUP, ES:NOTHING
  41.  
  42. TURN     proc      far            ; far process
  43.         
  44.          mov       ax,1           ; get first para
  45.          push      ax             ; push AX
  46.          call      _PARC          ; call Chara "getter"
  47.          add       sp,2           ; restore stack
  48.  
  49.          MOV       DI, BX         ; Offset of incoming param string
  50.          MOV       ES, AX         ; Segment of incoming param string
  51.         
  52.          ; DS is pointing to DGROUP
  53.          LEA       BX, DGROUP:RETVAL
  54.          MOV       DX, DS               ; Save DGROUP segment for later
  55.         
  56.          ; ES:DI point to start of parm string
  57.          ; DS:BX point to start of RETVAL
  58.          ; AX still holds parm string segment
  59.          ; DX also holds DGROUP/RETVAL segment
  60.          ; Now sort out null string special case
  61.          MOV       CL, ES:[DI]     ; Check for null parameter string
  62.          OR        CL, CL          ; Is it NULL?
  63.          JNZ       T010            ; Not zero, so skip, it's a regular string
  64.         
  65.          ;Null string special case
  66.          MOV       [BX], CL            ; Put a null into RETVAL
  67.          JMP       SHORT C3
  68.         
  69.         
  70.          ASSUME    DS:NOTHING
  71.  
  72. T010:    MOV       DS, AX              ; Also for later use as source
  73.         
  74.          ; Find terminating 0
  75.          cld                           ; String instructions upwards
  76.          MOV       CX, MAXLEN           ; Maximum length that RETVAL
  77.                                        ; can accommodate
  78.          SUB       AL, AL              ; Compare value - NUL, zero
  79.         
  80.          ; Check thru string for terminating 0
  81.          REPNE     SCASB               ; Look for nul
  82.          ; DI points one beyond 0
  83.          JNZ       T020                ; No terminating null found, 
  84.                                        ; counted down
  85.          ; Null found, DI points one beyond null
  86.          INC CX
  87.          DEC DI                   ; Now points to null
  88.         
  89. T020:    DEC       DI             ; And now points to last character
  90.          SUB       CX, MAXLEN    ; Negative length of string
  91.          NEG       CX             ; Actual length of string (except for nul)
  92.  
  93.          MOV       SI, DI         ; End of string is source
  94.                                   ; DS is already set to right segment
  95.          ;DS:SI point to last char of parm string
  96.          ;BX currently holds offset, DX segment of RETVAL
  97.          ;Move it into ES:DI
  98.          MOV       ES, DX         ; Save it for later in BX
  99.          ASSUME    ES:DGROUP
  100.          MOV       DI,BX
  101.  
  102. A3:      mov       al,[si]        ; Get a source character
  103.          dec       si             ; and point to next
  104.          STOSB                    ; and put AL into target pointed
  105.                                   ; to by ES:DI, autoincrement of DI
  106.          loop      A3             ; loop - count down CX
  107.     
  108.          xor       AL,AL          ; zero-out al
  109.          STOSB                    ; add null terminator to end
  110.                                   ; of RETVAL
  111.          ; DX:BX hold RETVAL starting offset
  112.          MOV       DS, DX         ; Restore original DS - DGROUP
  113.  
  114. C3:      PUSH      DS             ; Segment
  115.          PUSH      BX             ; Offset
  116.          call      _RETC          ; Clipper's  "returner"
  117.          ADD       SP, 4          ; Clean stack
  118.         
  119.          ret                      ; actual ret to caller
  120. TURN     endp                     ; end of process
  121.  
  122. _prog    ends                     ; end of segment
  123.          end                      ; end of programme
  124. ;
  125. ;
  126.